package com.simplesoftwares.client.library.appstructure.formscreen;


import com.simplesoftwares.client.library.FlexForm;
import com.simplesoftwares.client.library.FlexForm.FormStyle;
import com.simplesoftwares.client.library.appskeleton.ProcessLevelBar;
import com.simplesoftwares.client.library.appstructure.UiScreen;
import com.simplesoftwares.client.library.FormField;


/**
 * The Class FormScreen.
 * Repersents a FormScreen
 * @author Komal
 * @param <T> the generic type
 */
public abstract class FormScreen<T> extends  UiScreen<T>{
	

	/** The fields. 
	 * holds the formfield objects.This array is responsible for UI LAYOUT*/
	protected FormField[][]fields;
	
	/** The form. for creating the flexttable*/
	protected FlexForm form ;
	
	/** The formstyle.	decides the formStyle(rowform or coulmnform) */
	protected FormStyle formstyle;
	
	/** The default form style. */
	protected static FormStyle DEFAULT_FORM_STYLE=FormStyle.ROWFORM;

	 /**
 	 * Instantiates a new form screen.
 	 * Call to parameterized constructor with default_form_style(Rowform).
 	 */
 	protected FormScreen()
	 {
		 this(DEFAULT_FORM_STYLE);
	}
	 
	 /**
 	 * Instantiates a new form screen with passed formstyle.
 	 *	Instantiates the flexform with set fields & passed formstyle 
 	 *& instantiates the processlevel bar if the prosesslevel menus are not null 
 	 * @param formstyle the formstyle
 	 */
 	public FormScreen(FormStyle formstyle)
	 {
		 super();
		 this.formstyle=formstyle;
		form=new FlexForm(fields,formstyle);
		// create the process level bar and form add them in content
		if(processlevelBarNames!=null)
		{
			  processLevelBar= new ProcessLevelBar(5,processlevelBarNames);
			  processLevelBar.setVisibleFalse(false);
		}
	
	}
	 
	 /**
 	 * Instantiates a new form screen with passed processlevel menus,
 	 * fields & formstyle
 	 *
 	 * @param processlevel the processlevel menu names
 	 * @param fields the fields  The array of form field
 	 * @param formstyle the formstyle The default style of form
 	 */
 	public FormScreen( String[] processlevel,
			FormField[][] fields, FormStyle formstyle) 
	 {
		this(formstyle);
		this.processlevelBarNames = processlevel;
		this.fields = fields;
		this.formstyle = formstyle;
		
	}

///////////////////////////////////////////GUI CREATION/////////////////////////////////////////////
	 /*
	  * LOGICAL EXCEPTION TO B THROWN IF "fields & formstyle" ARE NOT INITIALIZED
	  */
	/* (non-Javadoc)
 * @see com.simplesoftwares.client.library.appstructure.ViewContainer#createGui()
 */
 	/**
 	 * Adds the processlevel bar on content if it is not null & adds the form on content
 	 */
@Override
	protected  void createGui() 
	{
		applyStyle();
		if(processlevelBarNames!=null)
		{
			content.add(processLevelBar.content);	
			
		}
		content.add(form);
		
	}

/////////////////////////////////////INHERITED METHODS(OVERRIDEN)/////////////////////////////////////////
	
	/* (non-Javadoc)
 * @see com.simplesoftwares.client.library.appstructure.UiScreen#clear()
 */
@Override
	public void clear() {
		form.clear();	
	}

	/* (non-Javadoc)
	 * @see com.simplesoftwares.client.library.appstructure.UiScreen#validate()
	 */
	@Override
	public boolean validate() {
		return form.validate();
		
	}
	
	/* (non-Javadoc)
	 * @see com.simplesoftwares.client.library.appstructure.UiScreen#setEnable(boolean)
	 */
	@Override
	public void setEnable(boolean state) {
		form.setEnabled(state);	
	}
	
	/* (non-Javadoc)
	 * @see com.simplesoftwares.client.library.appstructure.UiScreen#applyStyle()
	 */
	
	 public void applyStyle()
    {
		content.getElement().setId("formcontent");
		form.getElement().setId("form");
		
		
	}

///////////////////////////////////////////////////////////GETTER SETTERS///////////////////////////////////
	
	/**
 * Gets the bar.
 *
 * @return the bar
 */
public ProcessLevelBar getBar() {
		return processLevelBar;
	}


	/**
	 * Sets the bar.
	 *
	 * @param bar the new bar
	 */
	public void setBar(ProcessLevelBar bar) {
		this.processLevelBar = bar;
	}


	/**
	 * Gets the processlevel.
	 *
	 * @return the processlevel
	 */
	public String[] getProcesslevel() {
		return processlevelBarNames;
	}


	/**
	 * Sets the processlevel.
	 *
	 * @param processlevel the new processlevel
	 */
	public void setProcesslevel(String[] processlevel) {
		this.processlevelBarNames = processlevel;
	}


	/**
	 * Gets the fields.
	 *
	 * @return the fields
	 */
	public FormField[][] getFields() {
		return fields;
	}


	/**
	 * Sets the fields.
	 *
	 * @param fields the new fields
	 */
	public void setFields(FormField[][] fields) {
		this.fields = fields;
	}


	/**
	 * Gets the form.
	 *
	 * @return the form
	 */
	public FlexForm getForm() {
		return form;
	}


	/**
	 * Sets the form.
	 *
	 * @param form the new form
	 */
	public void setForm(FlexForm form) {
		this.form = form;
	}
    
 
	/**
	 * Gets the formstyle.
	 *
	 * @return the formstyle
	 */
	public FormStyle getFormstyle() {
		return formstyle;
	}

	/**
	 * Sets the formstyle.
	 *
	 * @param formstyle the new formstyle
	 */
	public void setFormstyle(FormStyle formstyle) {
		this.formstyle = formstyle;
	}
	
	

}
